import html2canvas from 'html2canvas'
import JsPDF from 'jspdf'
export const createdPdf = (targetDom, name, callback) => {
    return new Promise((res, rej) => {
        // const scale = window.devicePixelRatio;
        const scale = 2;

        html2canvas(targetDom, {
            dpi: scale,//导出pdf清晰度
            useCORS: true,  // 允许图片跨域
            // allowTaint: true, // 开启跨域
            scale, // 提升画面质量，但是会增加文件大小
            allowTaint: false
        }).then(function (canvas) {
            const contentWidth = canvas.width / scale;
            const contentHeight = canvas.height / scale;
            const PDF = new JsPDF('', 'pt', [contentWidth, contentHeight]);
            const pageData = canvas.toDataURL('image/jpeg', 1.0);
            PDF.addImage(pageData, 'JPEG', 0, 0, contentWidth, contentHeight);
            // #ifdef H5
            const fileName = uni.$u.timeFormat(new Date().getTime(), 'yyyy-mm-dd')
            PDF.save(fileName);
            res(true)
            // #endif
            // #ifdef APP-PLUS  
            const base64 = PDF.output('dataurlstring');
            res(base64)
            // #endif
        });
    })

}